import java.util.Scanner;

class Repo{
	String[] string;
	public boolean gender1 = true;
	public boolean gender2 = true;
	public Repo(String items) {
		string = items.split(" ");
	}
	int getSize(){
		int size = 0;
		for (int i = 0; i < this.string.length; i++) {
			if (string[i]!= null) size ++;
		}
		return size;
	}
	public void setGender1(boolean gender1) {
		this.gender1 = gender1;
	}
	public void setGender2(boolean gender2) {
		this.gender2 = gender2;
	}
	synchronized String deleteTask(){
		String str = string[0];
		for (int i = 0; i < string.length-1; i++) {
			string[i] = string[i+1];
		}
		string[string.length - 1] = null;
		return str;
	}
}
class Worker1 implements Runnable{
	private Repo repo;
	public Worker1(Repo repo) {
		// TODO Auto-generated constructor stub
		this.repo = repo;
	}

	@Override
	public void run() {
		// TODO Auto-generated method stub
		while (repo.getSize()!=0) {
			if (repo.gender1 == true){
				System.out.println(Thread.currentThread().getName()+" finish "+repo.deleteTask());
				repo.setGender1(false); 
				repo.setGender2(true);
			}
		}
		
	}	
}
class Worker2 implements Runnable{

	private Repo repo;
	public Worker2(Repo repo) {
		// TODO Auto-generated constructor stub
		this.repo = repo;
	}

	@Override
	public void run() {
		// TODO Auto-generated method stub
		while (repo.getSize()!=0) {
			if (repo.gender2 == true){
				System.out.println(Thread.currentThread().getName()+" finish "+repo.deleteTask());
				repo.setGender2(false); 
				repo.setGender1(true);
			}
		}		
	}
}